package org.vincen.helloworld.coding;

public class Base64 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(Base64.encodeBASE64("20130823_3304"));
		System.out.println(Base64.encodeBASE64("西安经发置业有限公司 - 现场勘验笔录"));

		System.out.println(Base64.decodeBASE64("MjAxMzA4MjNfMzMwNA=="));
		System.out
				.println(Base64
						.decodeBASE64("6KW/5a6J57uP5Y+R572u5Lia5pyJ6ZmQ5YWs5Y+4IC0g546w5Zy65YuY6aqM56yU5b2V"));
	}

	/**
	 * 对消息进行 BASE64 编码
	 * 
	 * @param s
	 *            消息
	 * @return
	 */
	public static String encodeBASE64(String s) {
		if (s == null)
			return null;
		return org.apache.commons.codec.binary.Base64.encodeBase64String(s
				.getBytes());
	}

	/**
	 * 对消息进行BASE64解码
	 * 
	 * @param s
	 *            消息
	 * @return
	 */
	public static String decodeBASE64(String s) {
		if (s == null)
			return null;
		byte[] bs = null;
		bs = org.apache.commons.codec.binary.Base64.decodeBase64(s);
		return new String(bs);
	}
}
